package com.jo.configuration;

import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Jo
 * @date 2017/12/6
 * 解决tomcat8.5X之后的bug
 */
@Configuration
public class CookieConfig {

    @Bean
    public EmbeddedServletContainerCustomizer customizer(){
        return container -> {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addContextCustomizers(
                    (TomcatContextCustomizer) context -> context.setCookieProcessor(new LegacyCookieProcessor()));
        };
    }
}
